<?php
            $this->headTitle($this->title);
             $this->headScript()->appendFile(Zend_Registry::get('static_path').'js/users.js');
            $this->headLink()->appendStylesheet(Zend_Registry::get('static_path').'css/user.css');
            $this->layout()->setLayout('userlayout');
?>
<div class="nav"><a href="<?php echo $this->url(array( 'controller' => 'resident', 'action'     => 'index'),'default', true) ?>" class="navlink">Control Panel</a><img src="../images/arrow.gif" class="arrow"/> View Documents</div>
<div id="userForm">
   <form name="search"  class="form" id="search" method="post" action="<?php echo $this->url(array( 'controller' => 'docs', 'action'     => 'view'),'default', true) ?>">
                <fieldset class="form">
                    <legend>Search a Document:</legend>
                    <table width="100%">
                        <tr>
                            <td width="15%">
                                <label>Document Name:</label>
                            </td>
                            <td width="25%">
                                <input type="text" name="_docName" value="<?php echo $this->docName ?>"/>
                            </td>
                            <td  width="5%">
                                <label>Category:</label>
                            </td>
                            <td width="20%">
                                  <select name="_category" id="category">
                                    <option value="">[--Select--]</option>
                                    <option value="Financial" <?php echo  ($this->category =="Financial") ?  "selected" :  "" ?>>Financial</option>
                                    <option value="Newsletter" <?php  echo  ($this->category =="Newsletter") ?  "selected" :  ""  ?>>Newsletter</option>
                                    <option value="Vendor"<?php echo  ($this->category =="Vendor") ?  "selected" :  ""   ?>>Vendor</option>
                            </select>
                            </td>
                            <td width="5%">
                                <label>Year:</label>
                            </td>
                            <td width="10%">
                                 <select name="_year" id="year"><option value="0">ALL</option></select>
                            </td>
                            <td width="30%" align="center">
                                 <input type="submit" value="Search"/>
                            </td>
                        </tr>
                    </table>
                </fieldset>
               <input type="hidden" name="action" value="_search"/>
        </form>
     <?php
                          if($this->searchData !=null){?>
                            <div id="searchData">
                                 <table class='searchresult1'>
                                      <thead>
                                          <tr>
                                              <td width="35%"><a href="javascript:;" class="headerlink" id="DOC_NAME" title="Click here to sort">Document Name</a><span id="DOC_NAME_SORT"></span></td>
                                              <td width="10%">File Size</td>
                                              <td width="15%"><a href="javascript:;" class="headerlink" id="CATEGORY"  title="Click here to sort">Category</a><span id="CATEGORY_SORT"></span></td>
                                               <td width="10%"><a href="javascript:;" class="headerlink" id="YEAR"  title="Click here to sort">Year</a><span id="YEAR_SORT"></span></td>
                                              <td width="35%"><a href="javascript:;" class="headerlink" id="CREATED_DATE"  title="Click here to sort">Added On</a><span id="CREATED_DATE_SORT"></span></td>
                                          </tr>
                                      </thead>
                                      <tbody>
                                          <?php foreach ($this->searchData as $data){ ?>
                                              <tr>
                                                <td><a href="../../docs/<?php echo $data->FILE_NAME  ?>"><?php echo $data->DOC_NAME  ?></a></td>
                                                <td><?php echo round((int)$data->FILE_SIZE/1000,2)  ?> MB</td>
                                                <td><?php echo $data->CATEGORY  ?></td>
                                                  <td><?php echo $data->YEAR  ?></td>
                                                 <td><?php echo date('F d, Y',strtotime($data->CREATED_DATE)) ?></td>
                                              </tr>
                                           <?php  }
                                            if (sizeof($this->searchData) ==0){ ?>
                                              <tr>
                                                  <td colspan ="5">
                                                      <font color="red">No Documents found. </font>
                                                  </td>
                                              </tr>
                                       <?php      }
                                            ?>
                                     </tbody>
                                 </table>
                                 </div>
                       <form name="mainForm"  class="form" id="mainForm" method="post" action="<?php echo $this->url(array( 'controller' => 'docs', 'action'     => 'view'),'default', true) ?>">
                              <input type="hidden" name="action" value=""/>
                              <input type="hidden" name="_docName" value="<?php echo $this->docName ?>"/>
                              <input type="hidden" name="_category" value="<?php echo $this->category ?>"/>
                               <input type="hidden" name="_year" value="<?php echo $this->year ?>"/>
                              <input type="hidden" name="_sortBy" id="_sortBy" value="<?php echo $this->sortBy ?>"/>
                       </form>
    <?php }
    ?>
</div>
<script>
    $(document).ready(function(){
        getYear(<?php echo $this->year ?>);


         if($("form#mainForm>input#_sortBy").val() !=""){
                var arr =$("form#mainForm>input#_sortBy").val().split(' ');
                var img="";
                if(arr[1]=="ASC"){
                    img="<img src='../images/asc.gif'/>";
                }else  if(arr[1]=="DESC"){
                     img="<img src='../images/desc.gif'/>";
                }
                $("#"+arr[0]+"_SORT").html(img);
            }
    });
</script>